import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ball_lion/resources/colours.dart';
import 'package:ball_lion/routes/routes.dart';
import 'package:ball_lion/entity/my/help/help_entity.dart';
import 'package:ball_lion/server/api/user_api.dart';
import 'package:ball_lion/utils/utils.dart';
import 'package:ball_lion/widgets/base/wqs_text.dart';
import 'package:ball_lion/widgets/ball_appbar.dart';
import 'package:ball_lion/widgets/card.dart';

enum FeedbackType { feedback, viewReport, liveReport }

class FeedbackChoicePage extends StatefulWidget {
  const FeedbackChoicePage({super.key}) : type = FeedbackType.feedback;
  const FeedbackChoicePage.viewReport({super.key})
      : type = FeedbackType.viewReport;
  const FeedbackChoicePage.liveReport({super.key})
      : type = FeedbackType.liveReport;

  final FeedbackType type;

  @override
  State<FeedbackChoicePage> createState() => _FeedbackChoicePageState();
}

class _FeedbackChoicePageState extends State<FeedbackChoicePage> {
  List<QuestionType> type = [];
  FeedbackType get feedbackType => widget.type;
  String info = Get.arguments ?? "";

  @override
  void initState() {
    getData();
    super.initState();
  }

  Future getData() async {
    List<String> viewReport = ["疑似抄袭他人方案", "方案内容与推荐比赛不符", "方案内容与推荐结果不符"];
    List<String> liveReport = ["涉政敏感", "违法违规", "淫秽色情", "侮辱谩骂", "引导微信交易", "其他"];
    List<QuestionType> list = await UserApi.getFeedbackType();
    int? id;
    if (feedbackType == FeedbackType.viewReport) {
      try {
        id = list.firstWhere((element) => element.name == "方案举报").id;
      } catch (e) {
        log(e.toString());
      }
      type = List.generate(3,
          (index) => QuestionType(id: id, name: viewReport[index], info: info));
    } else if (feedbackType == FeedbackType.liveReport) {
      try {
        id = list.firstWhere((element) => element.name == "直播举报").id;
      } catch (e) {
        log(e.toString());
      }
      type = List.generate(liveReport.length,
          (index) => QuestionType(id: id, name: liveReport[index], info: info));
    } else {
      type = list;
    }
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colours.greyF2F3F7,
        appBar: BallAppBar(
            title: "我要${feedbackType == FeedbackType.feedback ? "反馈" : "举报"}"),
        body: SizedBox(
            height: Get.height,
            child: SingleChildScrollView(
                child: Block(
                    cardStyle: const CardStyle(
                        margin: EdgeInsets.symmetric(horizontal: 8)),
                    child: Column(
                        children: type.map((e) => item(e)).toList().insertEvery(
                            const Divider(height: 0.5, color: Colours.greyEE)
                                .paddingSymmetric(horizontal: 12)))))));
  }

  Widget item(QuestionType? item) {
    return GestureDetector(
      onTap: () => Get.offAndToNamed(Routes.feedback, arguments: item),
      behavior: HitTestBehavior.translucent,
      child: Container(
        height: 52,
        padding: const EdgeInsets.symmetric(horizontal: 12),
        child: Row(children: [
          QsText(item?.name ?? "", fontSize: 16),
          const Spacer(),
          Image.asset(Utils.getImgPath("arrow_right.png"), width: 6, height: 10)
        ]),
      ),
    );
  }
}
